<?php
/**
 * @version 1.0
 * @since June-2008
 * @package lib
 * @subpackage struct
 * @name CZip
 * @deprecated thao tác với file zip
 *
 */
class CZip
{
	public $zip;
	public $file_name;
	public $saved = false;
	function __construct($file_name)
	{
		$this->file_name = $file_name;
		$this->zip = new ZipArchive();
	}
	function __destruct()
	{
		$this->zip->close(); 
	}
	function extract($path)
	{
		$this->zip->open($this->file_name); 
    	$this->zip->extractTo($path); 
	}
	function add($path, $put_into = '')
	{
		if(!$put_into)
		{
			if($pos = strpos($path, '/'))
			{
				$put_into = substr($path, $pos + 1);
			}
			else
			{
				$put_into = $path;
			}
		}
		if (!$this->saved and $this->zip->open($this->file_name, ZIPARCHIVE::CREATE)!==TRUE) 
		{
			throw new CExeption('ERROR', 'cannot open <'.$this->file_name.'>\n');
			$this->saved = true;
		}
		if(is_file($path))
		{
			$this->zip->addFile ($path, $put_into);
		}
		elseif(is_dir($path))
		{
			$this->zip->addEmptyDir ($put_into.'/');
			$handle = opendir($path);
			while (false !== ($file = readdir($handle))) 
			{
				if ($file != '.' and $file != '..')
				{
					$this->add($path.'/'.$file, $put_into.'/'.$file);
				}
			}
			closedir($handle);
		}
	}
}
function CZip($file_name)
{
	return new CZip($file_name);
}
?>